﻿$(document).ready(
    function() {
        if(!window.localStorage){
            new UserPrompt('您所使用的浏览器版本太低，或不支持本页面，请更换浏览器并重试！');
        }else{
			// 返回事件
			$('#twocalldetailsback').on('click', function() {
				var hasCached = meetCache.hasMeetStorage();
				var index = hasCached ? 10 : 0;
				router(index, '', true);
			});
			
            //获取url中传的值
            var queryString = decodeURI(window.location.search.substr(1));
            //获取josn字符串
            var josnString=matchQueryString(queryString,"data")||'';
            //判断获取的参数是否为空，如果为空则不获取
            var obj=""; 
            //手机号码
            var phoneNum,called;
            if(josnString!=''){
            	var param=JSON.parse(josnString);
                phoneNum=param['phoneNum'];
                called=param['called'];
            }
            
            //查询两方通话记录详情接口
            var diaDetailUrl = localCache.getSessionItem("dial_detail_url");
            
            //------------------向html中写值strat---------------------           
            //通话详情
            var content = $('#content');          
            $.ajax({
                type: "post",
                dataType: "json",
                url: diaDetailUrl,
                async: true,
                contentType:"application/x-www-form-urlencoded; charset=UTF-8",
                data: {
                    'phoneNum': phoneNum,
                    'called':called
                },
				beforeSend:function(){
					loadPrompt=new LoadPrompt('数据加载中...');
				},
                success: function (json) {
                    if (json['result'] == '0') {
                    	var dataJsonArray = json.data;
                        for(var i=0;i<dataJsonArray.length;i++){
                        	var dataJson = dataJsonArray[i];
                        	var createTimeDay = dataJson.createTimeDay;
                        	var createTimeHour = dataJson.createTimeHour;
                        	var caller = dataJson.caller; //主叫
                        	var callerIndex = caller.indexOf(phoneNum); //callerIndex=-1时是呼入，反之为呼出
                        	var time = formatSeconds(dataJson.time);
                        	var callTypeText = '呼出';
                        	var callTypeImage = 'out.png';
                        	if(callerIndex == -1){
                        		callTypeText = '来电';
                        		callTypeImage = 'come2.png';
                        	}
                        	                       	
                        	content.append(
                    				' <dl> ' +
                    				'	<dt><b>' + createTimeDay + '</b><i>' + createTimeHour + '</i></dt> ' +
                    				'	<dd> ' +
                    				'		<span class="txt">' + callTypeText + '</span> ' +
                    				'		<i><img src="images/' + callTypeImage + '" width="14" height="14"/></i> ' +
                    				'       <span class="time">' + time + '</span> ' +
                    				'   </dd> ' +
                    				' </dl> ');
                        }
                    } else {
                        new UserPrompt(json['describe']+"请稍后再试！");  
                    }
                },
                error: function (json) {
                    new UserPrompt("连接异常，请稍后再试！");
                },
                complete: function () {
					if(loadPrompt){
						loadPrompt.close();
						loadPrompt=null;
					}
                }
            });
            //------------------向html中写值end---------------------
            
            //------------------格式化时间函数begin---------------------
            function formatSeconds(value) { 
            	var theTime = parseInt(value);// 秒 
            	var theTime1 = 0;// 分 
            	var theTime2 = 0;// 小时 
            	if(theTime > 60) { 
	            	theTime1 = parseInt(theTime/60); 
	            	theTime = parseInt(theTime%60);  
	            	if(theTime1 > 60) { 
		            	theTime2 = parseInt(theTime1/60); 
		            	theTime1 = parseInt(theTime1%60); 
	            	} 
            	} 
            	var result = ""+parseInt(theTime)+"秒"; 
            	if(theTime1 > 0) { 
            		result = ""+parseInt(theTime1)+"分"+result; 
            	} 
            	if(theTime2 > 0) { 
            		result = ""+parseInt(theTime2)+"小时"+result; 
            	} 
            	return result; 
            }
            //------------------格式化时间函数end---------------------
        }
    }
);